#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define int unsigned long long
using namespace std;
 
int get_ans(map<int, int, greater<int>>& cnt)
{
	int ans = 0;
	int line = 0;
	int two = 2;
	for (auto& e : cnt)
	{
		if (e.second > 1)
		{
			ans += e.first * (e.second / 2) * 2;
			line += (e.second / 2) * 2;
		}
		if (e.second % 2 == 1 && two)
		{
			--two;
			++line;
			ans += e.first;
		}
	}
	if (line < 3) return 0;
 
	if (ans / 2 + ans % 2 <= cnt.begin()->first)
	{
		if (line == 3) return 0;
		else
		{
			cnt.erase(cnt.begin());
			return get_ans(cnt);
		}
	}
	else
		return ans;
}
 
void solve()
{
	int n; cin >> n;
	map<int, int, greater<int>> cnt;
	while (n--)
	{
		int tmp; cin >> tmp;
		++cnt[tmp];
	}
	cout << get_ans(cnt) << endl;	
}
 
signed main()
{
	int t; cin >> t;
	while (t--) solve();
	return 0;
}
 
//7 8 999 4 4 4 3 3 3 3 5 6 6 4 4 4 3 5 5 7 3 4 5 7 3 5 5 11 7 4 3 5 1 5 3 3 4 2 3 5 7